﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using _619BJP.Models;
using _619BJP.Database.admin;
using System.Data;
using _619BJP.Database.Article;

namespace _619BJP.Web.Controllers
{
    public class ArticleController : Controller
    {
        //
        // GET: /Article/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult ArticleIndex()
        {
            return View();
        }

        /// <summary>
        /// 百科详细
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult ArticleDetails(int id)
        {
            articleDB articleDB = new articleDB();
            ArticleModel articelModel = articleDB.articleDetail(id);

            ViewData.Model = articelModel;
            ViewData["Title"] = articelModel.title + "-";
            return View();
        }

        /// <summary>
        /// 前一篇百科
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ArticleModel PreArticle(int id)
        {
            articleDB articleDB = new articleDB();
            ArticleModel articelModel = articleDB.preArticle(id);
            return articelModel;
        }

        /// <summary>
        /// 下一篇百科
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ArticleModel NextArticle(int id)
        {
            articleDB articleDB = new articleDB();
            ArticleModel articelModel = articleDB.nextArticle(id);
            return articelModel;
        }

        /// <summary>
        /// 具体类别下的文章列表
        /// </summary>
        /// <param name="category_id"></param>
        /// <returns></returns>
        public ActionResult ArticleList(int id,string keyword)
        {
            if (id != 0)
            {
                articleDB articleDB = new articleDB();
                ViewData.Model = articleDB.GetArticleByCategory(id);
                ViewData["CategoryID"] = id;
                return View();
            }
            else {
                articleDB articleDB = new articleDB();
                ViewData.Model = articleDB.GetArticleByKeyword(keyword);
                ViewData["keyWord"] = keyword;
                return View();
            }
        }

        /// <summary>
        /// 今日焦点
        /// </summary>
        /// <returns></returns>
        public DataSet GetDailyArticle()
        {
            articleDB articleDB = new articleDB();
            DataSet ds = articleDB.GetDailyArticle();
            return ds;
        }

        /// <summary>
        /// 本周热点
        /// </summary>
        /// <returns></returns>
        public DataSet GetWeeklyArticle()
        {
            articleDB articleDB = new articleDB();
            DataSet ds = articleDB.GetWeeklyArticle();
            return ds;
        }

        /// <summary>
        /// 百科类别列表
        /// </summary>
        /// <returns></returns>
        public DataSet GetArticleCategory()
        { 
            articleDB articleDB = new articleDB();
            DataSet ds = articleDB.GetArticleCategory();
            return ds;
        }

        /// <summary>
        /// 具体类别下的文章
        /// </summary>
        /// <param name="category_id"></param>
        /// <returns></returns>
        public DataSet GetArticleByCategory(int category_id)
        {
            articleDB articleDB = new articleDB();
            DataSet ds = articleDB.GetArticleByCategory(category_id);
            return ds;
        }

        /// <summary>
        /// 最热文章
        /// </summary>
        /// <returns></returns>
        public DataSet GetHotArticle()
        {
            articleDB articleDB = new articleDB();
            DataSet ds = articleDB.GetHot();
            return ds;
        }

        /// <summary>
        /// 最新文章
        /// </summary>
        /// <returns></returns>
        public DataSet GetNewArticle()
        {
            articleDB articleDB = new articleDB();
            DataSet ds = articleDB.GetNew();
            return ds;
        }

        ///// <summary>
        ///// 根据关键字搜索
        ///// </summary>
        ///// <param name="keyWord"></param>
        ///// <returns></returns>
        //public ActionResult ArticleList(string keyWord)
        //{
        //    articleDB articleDB = new articleDB();
        //    ViewData.Model = articleDB.GetArticleByKeyword(keyWord);
        //    ViewData["keyWord"] = keyWord;
        //    return View();
        //}

        /// <summary>
        /// 缩写
        /// </summary>
        /// <param name="title"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public string TitleForShort(string title,int count)
        {
            if (title.Length >= count)
            {
                title = title.Substring(0, count) + " ...";
            }
            return title;
        }

    }
}
